using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Diagnostics;

namespace DailyTransaction
{
    public partial class frmMain : Form
    {
        private frmBatchUpdate frmbupd = null;
        private frmLogin frmlogin = null ;
        private frmInputUser frmuser=null;
        private frmDailyChecking frmchecking = null;
        private frmVoidUpd frmvoidUpd = null;
        private frmCreatCOMP frmCrtCOMP = null;
        private frmDailyListing frmDaily = null;
        private frmMaint_AccountCode frmAcctCode = null;
        public int role;
        const int ERROR_FILE_NOT_FOUND = 2;
        const int ERROR_ACCESS_DENIED = 5;
        public frmMain()
        {
            InitializeComponent();
        }

        private void linkBatchUpdate_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            if (frmbupd == null || frmbupd.IsDisposed == true)
                frmbupd = new frmBatchUpdate();
            frmbupd.ShowDialog();
            frmbupd.Focus();
        }

        private void linkDailyChecking_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            //if (frmlogin == null || frmlogin.IsDisposed == true)
            //    frmlogin = new frmLogin();
            //frmlogin.ShowDialog();
            //frmlogin.Focus();
            if (frmchecking == null || frmchecking.IsDisposed == true)
                frmchecking = new frmDailyChecking();
            frmchecking.role = GlobalClass.role;
            frmchecking.Show();
        }

        private void linkAdduser_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            if (frmuser == null || frmuser.IsDisposed == true)
                frmuser = new frmInputUser();
            frmuser.Show();
        }

        private void frmMain_Load(object sender, EventArgs e)
        {
            GlobalClass.islogin = false;
            if (frmlogin == null || frmlogin.IsDisposed == true)
                frmlogin = new frmLogin();
            frmlogin.ShowDialog();

            /*GlobalClass.islogin = true;
            GlobalClass.user = "tu";
            GlobalClass.role = 1;*/
        }

        private void frmMain_Shown(object sender, EventArgs e)
        {
            if (GlobalClass.islogin == false)
            {
                this.Close();
            }
            if (GlobalClass.role != 1)
                linkAdduser.Visible = false;
            txtuser.Text = GlobalClass.user;
            txtrole.Text = GlobalClass.role.ToString();
            txtConnectionStr.Text = GlobalClass.servername;
        }

        private void btnClose_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void lnkChangeConnect_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            /*Process chngProc = new Process();

            try
            {
                // Get the path that stores user documents.
                string myDocumentsPath =
                    Environment.GetFolderPath(Environment.SpecialFolder.Personal);
                string myPath = Environment.CurrentDirectory;

                chngProc.StartInfo.FileName = myPath + "\\DailyCheckingConfig.exe";
                //chngProc.StartInfo.CreateNoWindow = true;

                chngProc.Start();
            }
            catch (Win32Exception ex)
            {
                if (ex.NativeErrorCode == ERROR_FILE_NOT_FOUND)
                {
                    Console.WriteLine(ex.Message + ". Check the path.");
                }

                else if (ex.NativeErrorCode == ERROR_ACCESS_DENIED)
                {
                    // Note that if your word processor might generate exceptions
                    // such as this, which are handled first.
                    Console.WriteLine(ex.Message +
                        ". You do not have permission to access this file.");
                }
            }*/
        }

        private void lnkVoidUpd_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            if (frmvoidUpd == null || frmvoidUpd.IsDisposed == true)
                frmvoidUpd = new frmVoidUpd();
            frmvoidUpd.Show();
            frmvoidUpd.Focus();
        }

        private void lnkCreateCOMP_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            if (frmCrtCOMP == null || frmCrtCOMP.IsDisposed == true)
                frmCrtCOMP = new frmCreatCOMP();
            frmCrtCOMP.role = GlobalClass.role;
            frmCrtCOMP.Show();
        }

        private void linkDailyTrans_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            if (frmDaily == null || frmDaily.IsDisposed == true)
                frmDaily = new frmDailyListing();
            //frmDaily.role = GlobalClass.role;
            frmDaily.Show();
        }

        private void linkMaintainAB_ACCOUNT_CODE_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            if (frmAcctCode == null || frmAcctCode.IsDisposed == true)
                frmAcctCode = new frmMaint_AccountCode();
            frmAcctCode.Show();
        }
    }
}